package my.io.hadoop.config;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.mapreduce.lib.db.DBConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.context.annotation.Bean;

import java.io.IOException;

@org.springframework.context.annotation.Configuration("HadoopConfigInit")
public class HadoopConfig {


    @Bean
    public Configuration hadoopConfig(DataSourceProperties dbProperties) {
        Configuration configuration = new Configuration();
        DBConfiguration.configureDB(configuration, dbProperties.getDriverClassName(),
                dbProperties.getUrl(), dbProperties.getUsername(), dbProperties.getPassword());
        return configuration;
    }

    @Bean
    public FileSystem fileSystem(Configuration hadoopConfig) throws IOException {
        return FileSystem.get(hadoopConfig);
    }
}
